package linear_list.leetcode.easy;

/**
 * @author bruin_du
 * @description 链表中倒数第k个节点
 * @date 2022/5/26 20:05
 **/
public class Offer22_GetKthFromEnd {
    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode cur = head,prev = head;
        for (int i = 0; i < k; i++) {
            cur = cur.next;
        }
        while(cur != null){
            cur = cur.next;
            prev = prev.next;
        }
        return prev;
    }
}
